const http = require('http');
const fs = require('fs');

// 第一种写法
const sv = http.createServer((req, res) => {
    let { pathname } = new URL(req.url,`http://${req.headers.host}`);
    console.log(pathname);

    if (pathname === '/') {
        let html = fs.readFileSync(__dirname + '/index.html');
        res.end(html);
    }else if(pathname === '/index.css') {
        let css = fs.readFileSync(__dirname + '/index.css');
        res.end(css);
    }else if(pathname === '/index.js') {
        let js = fs.readFileSync(__dirname + '/index.js');
        res.end(js);
    }else {
        res.end('Not Found 404')
    }

    // 第二种写法，看响应练习02
});



sv.listen(3000,()=>{
    console.log('Server is running at http://localhost:3000');
});